package com.vca.admin.controller;

import com.vca.common.model.course.CourseScheduling;
import com.vca.common.page.CommonPage;
import com.vca.common.request.*;
import com.vca.common.response.AdminHeaderResponse;
import com.vca.common.response.CourseSchedulingAdminByIdResponse;
import com.vca.common.response.ExhibitionSchedulingAdminResponse;
import com.vca.common.result.CommonResult;
import com.vca.common.response.ExhibitionSchedulingAdminByIdResponse;
import com.vca.common.vo.ExcelCourseSchedulingById;
import com.vca.common.vo.ExcelExSchedulingById;
import com.vca.service.service.ExhibitionSchedulingService;
import com.vca.service.service.ExhibitionService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 展览排课控制器
 *
 * @author Li
 * @date 2022/11/14   13:15
 */
@Slf4j
@RestController("ExhibitionSchedulingController")
@RequestMapping("api/admin/exhibition/scheduling")
@Api(tags = "展览排课控制器")
public class ExhibitionSchedulingController {

    @Autowired
    private ExhibitionSchedulingService exhibitionSchedulingService;

    @Autowired
    private ExhibitionService exhibitionService;

    /**
     * 展览排课管理
     * @param request
     * @param pageParamRequest
     * @author Li
     * @date    2022/11/16 15:06
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:list')")
    @ApiOperation("展览排课管理")
    @GetMapping("/list")
    public CommonResult<CommonPage<ExhibitionSchedulingAdminResponse>> getList(@ModelAttribute @Validated SchedulingAdminListRequest request, @ModelAttribute PageParamRequest pageParamRequest){
        CommonPage commonPage = CommonPage.restPage(exhibitionSchedulingService.getAdminList(request,pageParamRequest));
        return CommonResult.success(commonPage);
    }


    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:getBookingDetail')")
    @ApiOperation(value = "查看预约明细")
    @GetMapping("/getBookingDetail")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "排期id", name = "排期id")
    )
    public CommonResult<ExcelExSchedulingById> getBookingDetail(String id, PageParamRequest pageParamRequest) {
        return CommonResult.success(exhibitionSchedulingService.getBookingDetail(id,pageParamRequest));
    }

    /**
     * 展览排期日历列表
     * @author Li
     * @date 2022/11/21 11:19
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:calendar')")
    @ApiOperation(value = "展览排期列日历列表")
    @GetMapping("/calendarList")
    public CommonResult getCalendarList(@ModelAttribute @Validated SchedulingAdminListRequest request){
        return CommonResult.success(exhibitionSchedulingService.getCalendarList(request));
    }

    /**
     * 添加展览排期
     * @author Li
     * @date  2022/11/21 11:19
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:add')")
    @ApiOperation(value = "添加展览排期")
    @PostMapping("/addScheduling")
    public CommonResult addScheduling(@RequestBody SchedulingAddRequest<ExhibitionSchedulingAddRequest> request){
        return exhibitionSchedulingService.addScheduling(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 修改展览排期
     * @author Li
     * @date  2022/11/21   11:19
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:update')")
    @ApiOperation(value = "修改展览排期")
    @PostMapping("/updateScheduling")
    public CommonResult updateScheduling(@RequestBody ExhibitionSchedulingAddRequest request){
        return exhibitionSchedulingService.updateScheduling(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 排期id查询排期
     * @param exhibitionId
     * @author Li
     * @date 2022/11/21 09:47
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:get')")
    @ApiOperation(value = "排期id查询排期")
    @GetMapping("/getScheduling")
    public CommonResult<ExhibitionSchedulingAdminByIdResponse> getAdminScheduling(Long exhibitionId){
        return CommonResult.success(exhibitionSchedulingService.getAdminScheduling(exhibitionId));
    }

    /**
     * 根据展览排期id删除排期
     * @param schedulingId
     * @author Li
     * @date  2022/11/21   15:02
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:delete')")
    @ApiOperation(value = "根据展览排期id删除排期")
    @GetMapping("/deleteScheduling")
    public CommonResult deleteScheduling(Long schedulingId){
        return exhibitionSchedulingService.deleteScheduling(schedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 跟据展览id查询排期
     *
     * @param exhibitionId
     * @param pageParamRequest
     * @return
     * @author Li
     * @date 2022/11/21 09:47
     */
    @ApiOperation(value = "跟据展览id查询排期")
    @GetMapping("/getListByExhibition")
    public CommonResult<CommonPage<ExhibitionSchedulingAdminByIdResponse>> getListByExhibition(Long exhibitionId, @ModelAttribute PageParamRequest pageParamRequest){
        CommonPage commonPage = CommonPage.restPage(exhibitionSchedulingService.getListByExhibition(exhibitionId,pageParamRequest));
        return CommonResult.success(commonPage);
    }

    /**
     * @author Li
     * @date  2022/11/24
     * @return
     */
    @ApiOperation(value = "获得展览排期头部数据")
    @GetMapping("/header")
    public CommonResult<List<AdminHeaderResponse>> getHeader(String dateLimit) {
        return CommonResult.success(exhibitionSchedulingService.getHeader(dateLimit));
    }

    /**
     * 上架展览排期预约状态
     * @param exhibitionSchedulingId 展览排期id
     * @author Li
     * @date    2022/11/18 15:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:shell:on')")
    @ApiOperation("上架展览排期预约状态")
    @GetMapping("/onShell")
    public CommonResult courseOnShell(Long exhibitionSchedulingId){
        return exhibitionSchedulingService.onShell(exhibitionSchedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 下架展览排期预约状态
     * @param exhibitionSchedulingId 展览排期id
     * @author Li
     * @date    2022/11/18 15:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:shell:off')")
    @ApiOperation("下架展览排期预约状态")
    @GetMapping("/offShell")
    public CommonResult courseOffShell(Long exhibitionSchedulingId){
        return exhibitionSchedulingService.offShell(exhibitionSchedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
    * @description 批量删除排期
    * @param schedulingIds
    * @author Li
    * @date 2022/11/29 11:28
    * @return com.vca.common.result.CommonResult
    */
    @ApiOperation("批量删除排期")
    @PostMapping("/deleteByIds")
    public CommonResult updateAll(@RequestBody List<Long> schedulingIds){
        return exhibitionSchedulingService.updateAll(schedulingIds)?CommonResult.success():CommonResult.failed();
    }

    /**
     * @description  取消展览排期
     * @methodName cancel
     * @param request
     * @author Li
     * @date 2022/12/28 16:19
     * @return com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:exhibition:scheduling:cancel')")
    @ApiOperation("取消展览排期")
    @PostMapping("/cancel")
    public CommonResult cancel(@RequestBody SchedulingCancelRequest request){
        return exhibitionSchedulingService.cancel(request)?CommonResult.success():CommonResult.failed();
    }
}
